local juxia = fk.CreateSkill {

  name = "joy__juxia",

  tags = { Skill.Compulsory, },

}



juxia:addEffect(fk.PindianResultConfirmed, {
  name = "joy__juxia",
  anim_type = "special",
  priority = 2.11,
  mute = true,
  frequency = Skill.Compulsory,
  events ={fk.PindianResultConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(juxia.name) then
      if event == fk.PindianResultConfirmed then
        if player == data.from then
          return data.fromCard.number == 1
        elseif player == data.to then
          return data.toCard.number == 1
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
      return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PindianResultConfirmed then
      player.room:notifySkillInvoked(player,juxia.name)
      player:broadcastSkillInvoke(juxia.name)
      data.winner = player
      local pd_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Pindian)
      if pd_event then
        local pdata = pd_event.data[1]
        if player == pdata.from then
          if pdata.fromCard.number == 1 then
            for _, p in ipairs(player.room.players) do
              if pdata.results[p.id] then
                pdata.results[p.id].winner = player
              end
            end
          end
        elseif pdata.results[player.id] then
          if pdata.results[player.id].toCard.number == 1 then
            pdata.results[player.id].winner = player
          end
        end
      end
      player.room:sendLog{
        type = "#joy__juxia",
        from = player.id,
        arg = juxia.name,
      }
    end
  end,
})

return juxia